#define _CRT_SECURE_NO_WARNINGS  1
#include <stdio.h>

int main() {
    long long int n;
    scanf("%lld", &n);
    long long int arr[1000];
    int i = 0;
    for (i = 0; i < n; i++)
    {
        scanf("%lld", &arr[i]);
    }
    long long int max[3] = { 0 };
    long long int min[2] = { 0 };
    int j = 0;
    int p = 0;
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (max[i] < arr[j])
            {
                max[i] = arr[j];
                p = j;
            }
        }
        arr[p] = 0;
    }
    for (i = 0; i < 2; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (min[i] > arr[j])
            {
                min[i] = arr[j];
                p = j;
            }
        }
        arr[p] = 0;
    }
    long long int ret = 0;
    if ((max[1] * max[2]) > (min[0] * min[1]))
    {
        ret = max[0] * max[1] * max[2];
    }
    else
    {
        ret = max[0] * min[0] * min[1];

    }
    printf("%lld", ret);
}